package IOStream;

import java.io.*;

/*
    用字符流来复制一个文本文件
 */
public class ReaderAndWriter {
    public static void main(String[] args) {
        File file1=new File("c:\\IOStream\\copy.txt");
        File file2=new File("c:\\IOStream\\copy01.txt");
        FileReader fr=null;
        BufferedReader br=null;
        FileWriter fw=null;
        BufferedWriter bw=null;
        try {
            fr=new FileReader(file1);
            fw=new FileWriter(file2);
            br=new BufferedReader(fr);
            bw=new BufferedWriter(fw);
            String str;
            while ((str=br.readLine())!=null){
                bw.write(str);
                bw.newLine();
            }
            bw.flush();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                fr.close();
                fw.close();
                br.close();
                bw.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
